package com.example.yang.mvp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.yang.mvp.m.M1;
import com.example.yang.mvp.m.M2;
import com.example.yang.mvp.p.P1;
import com.example.yang.mvp.p.P2;
import com.example.yang.mvp.v.ViewMain;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements ViewMain, XRecyclerView.LoadingListener {
        private  int page=1;
        private XRecyclerView re;
        private List<Bean.RESULTBean.NewsListBean>  listBeans = new ArrayList<>();
        private Myadapter myadapter;
    private P2 p2;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);


            initView();

        p2 = new P1(this,new M1());
        p2.setPage(page);


        }

        private void initView() {
            re = (XRecyclerView) findViewById(R.id.re);
            re.setLoadingListener(this);


            myadapter = new Myadapter(listBeans,MainActivity.this);
            re.setAdapter(myadapter);

            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
            re.setLayoutManager(linearLayoutManager);



        }

        @Override
        public void ShowList(List<Bean.RESULTBean.NewsListBean> list) {


            listBeans.addAll(list);
            myadapter.notifyDataSetChanged();



        }

    @Override
    public void onRefresh() {
      page=1;
      p2.setPage(page);

        re.refreshComplete();
    }

    @Override
    public void onLoadMore() {
        page++;
        p2.setPage(page);

        re.loadMoreComplete();

    }
}
